<template>
  <div>
    <div>API 数据</div>
    <div class="response-box">{{ sdkResponse || '--' }}</div>
    <div>mqtt 数据</div>
    <div class="response-box">{{ mqttResponse || '--' }}</div>
    <div class="button">
      <!-- Mqtt连接按钮 -->
      <button @click="connectToMqtt()">连接Mqtt</button>

      <!-- 日报告相关操作按钮 -->
      <button @click="dayReportPreForceGenerate()">日报告-手动生成报告</button>
      <button @click="getDaySleepById()">日报告-通过报告ID获取报告详情</button>
      <button @click="getDaySleep()">日报告-获取指定日期设备最新报告</button>
      <button @click="getDaySleepCalendar()">日报告-获取设备日历统计数据</button>

      <!-- 周报告相关操作按钮 -->
      <button @click="getWeekSleepById()">周月报告-通过报告ID获取报告详情(周)</button>
      <button @click="getWeekSleep()">周月报告-获取指定日期设备最新报告(周)</button>
      <button @click="getWeekSleepCalendar()">周月报告-获取设备日历统计数据(周)</button>

      <!-- 月报告相关操作按钮 -->
      <button @click="getMonthSleepById()">周月报告-通过报告ID获取报告详情(月)</button>
      <button @click="getMonthSleep()">周月报告-获取指定日期设备最新报告(月)</button>
      <button @click="getMonthSleepCalendar()">周月报告-获取设备日历统计数据(月)</button>

      <!-- 调节参数获取按钮 -->
      <button @click="adjustMatch()">根据性别、年龄、身高、体重获取调节数据</button>
    </div>
  </div>
</template>

<script>


export default {
  name: 'App',
  data() {
    return {
      sdkResponse: "",
      mqttResponse: "",
    }
  },
  mounted() {
    // derucci.setDebugMode(true);
    // 设置环境为测试环境
    derucci.setEnv("test");
    // 添加MQTT事件监听器
    this.addMqttEventListener();
  },
  methods: {
    async connectToMqtt() {
      await derucci.connectToMqtt("08A6F75AFE20");
    },
    addMqttEventListener() {
      derucci.addMqttEventListener("t10ProHwzxRtDataNotify", (data) => {
        this.mqttResponse = data;
      });
    },
    async dayReportPreForceGenerate() {
      this.sdkResponse = await derucci.dayReportPreForceGenerate({
        machineCode: "08A6F75AFE20",
        machineUniqueCode: "08A6F75AFE20####left"
      });
    },
    async getDaySleepById() {
      this.sdkResponse = await derucci.getDaySleepById({
          docId: "683132ae34443d000122ca10",
          machineUniqueCode: "08A6F75AFE20####left"
      });
    },
    async getDaySleep() {
      this.sdkResponse = await derucci.getDaySleep({
        docDate: "2024/12/31",
        machineUniqueCode: "08A6F75AFE20####left",
      });
    },

    // 获取设备日历统计数据的日报告方法
    async getDaySleepCalendar() {
      this.sdkResponse = await derucci.getDaySleepCalendar({
        docDate: "2024/03/02",
        machineUniqueCode: "08A6F75AFE20####left",
      });
    },

    // 通过报告ID获取周报告详情的方法
    async getWeekSleepById() {
      this.sdkResponse = await derucci.getWeekMonthSleepById({
        docId: "682fdd1534443d000122c9e1",
        machineUniqueCode: "08A6F75AFE20####left"
      });
    },

    // 获取指定日期设备最新周报告的方法
    async getWeekSleep() {
      this.sdkResponse = await derucci.getWeekMonthSleep({
        periodType: "week", // week、month
        docDate: undefined,
        machineUniqueCode: "08A6F75AFE20####left",
      });
    },

    // 获取设备日历统计数据的周报告方法
    async getWeekSleepCalendar() {
      this.sdkResponse = await derucci.getWeekMonthSleepCalendar({
        periodType: "week", // week、month
        docDate: "2025/03/01",
        machineUniqueCode: "08A6F75AFE20####left",
      });
    },


    // 通过报告ID获取月报告详情的方法
    async getMonthSleepById() {
      this.sdkResponse = await derucci.getWeekMonthSleepById({
        docId: "682fdd0834443d000122c9c0",
        machineUniqueCode: "08A6F75AFE20####left"
      });
    },

    // 获取指定日期设备最新月报告的方法
    async getMonthSleep() {
      this.sdkResponse = await derucci.getWeekMonthSleep({
        periodType: "month", // week、month
        docDate: undefined,
        machineUniqueCode: "08A6F75AFE20####left",
      });
    },

    // 获取设备日历统计数据的月报告方法
    async getMonthSleepCalendar() {
      this.sdkResponse = await derucci.getWeekMonthSleepCalendar({
        periodType: "month", // week、month
        docDate: "2025/02/01",
        machineUniqueCode: "08A6F75AFE20####left",
      });
    },

    // 根据性别、年龄、身高、体重获取调节数据的方法
    adjustMatch() {
      const res = derucci.adjustMatch({
        gender: "female",
        age: 30,
        height: 170,
        weight: 65
      })
      alert(`调节参数为：${res}`); // 弹出调节参数结果
    }

  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
}
.response-box {
  width: 100%;
  box-sizing: border-box;
  height: 20vh;
  border: 1px solid #ccc;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
  overflow-y: scroll;
}
body {
  padding: 10px;
}
input {
  width: 100%;
  border: 1px solid #ccc;
  border-radius: 10px;
  padding: 10px;
  box-sizing: border-box;
}
button {
  margin: 10px;
  padding: 10px;
  width: calc(50vw - 30px);
}

</style>
